{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from geoscilabs.dcip.DCIP_overburden_PseudoSection import (\n",
    "    DCIP2DfwdWidget, DC2Dsurvey, PseudoSectionWidget, mesh\n",
    ")\n",
    "from IPython.display import display"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Effects of a highly Conductive surface layer"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Purpose \n",
    "\n",
    "For a direct current resistivity (DCR)  or Induced Polarization (IP) survey, currents are injected to the earth, and flow. \n",
    "Depending upon the conductivity and chargeability contrasts current flow in the earth will be distorted, and these changes \n",
    "can be measurable on the sufurface electrodes. \n",
    "Here, we focus on a bloc target embedded in a halfspace below a highly conductive surface layer, and investigate what are happening in the earth when static currents are injected. The conductive layer will also impact the illumination of the target (conductor or resistor).\n",
    "By investigating in data upon different physical properties contrasts, we explore the sensitivity of these surveys to the target."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Setup"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<img src=\"https://github.com/geoscixyz/geosci-labs/blob/master/images/em/Dcapps_Overburden_draw.png?raw=true\" />"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Parameters\n",
    " - **$\\rho_{1}$**: Resistivity of the half-space\n",
    " - **$\\rho_{2}$**: Resistivity of the overburden\n",
    " - **$\\rho_{3}$**: Resistivity of the target\n",
    " - **$\\eta_{1}$**: Chargeability of the half-space\n",
    " - **$\\eta_{2}$**: Chargeability of the overburden\n",
    " - **$\\eta_{3}$**: Chargeability of the target\n",
    " - **Overburden_thick**: thickness of the overburden\n",
    " - **target_thick**: thickness of the target\n",
    " - **target_wide**: width of the target\n",
    " - **ellips_a**: x radius of ellipse\n",
    " - **ellips_b**: z radius of ellipse\n",
    " - **xc**: x location of ellipse center\n",
    " - **zc**: z location of ellipse center\n",
    " - **predmis**: Compare the Observed data to the ones without a target, see either the data (Overburden), or the difference between the two\n",
    " - **Array Type**: Type of array\n",
    " - **Rx per Tx**: How many receivers per sources\n",
    " - **Survey**: DC or IP\n",
    " - **Scale**: Linear or Log Scale visualization\n",
    " \n",
    "###  **When typing modifications to values, do not forget to PRESS ENTER**\n",
    "\n",
    "### **Warning: This app is only in 2D, which means sources are infinite lines instead of point sources as in 2.5D or 3Dcodes **"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1f890bb1f90c4a92bdee4b62a6315bb3",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "MyApp(children=(FloatText(value=1000.0, description='$\\\\rho_1$'), FloatText(value=100.0, description='$\\\\rho_2…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "test = DCIP2DfwdWidget();\n",
    "display(test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Appendix: Building Pseudosections \n",
    "\n",
    "2D profiles are often plotted as pseudo-sections by extending $45^{\\circ}$ lines downwards from the A-B and M-N midpoints and plotting the corresponding $\\Delta V_{MN}$, $\\rho_a$, or misfit value at the intersection of these lines as shown below. For pole-dipole or dipole-pole surveys the $45^{\\circ}$ line is simply extended from the location of the pole. By using this method of plotting, the long offset electrodes plot deeper than those with short offsets. This provides a rough idea of the region sampled by each data point, but the vertical axis of a pseudo-section is not a true depth.\n",
    "\n",
    "In the widget below the red dot marks the midpoint of the current dipole or the location of the A electrode location in a pole-dipole array while the green dots mark the midpoints of the potential dipoles or M electrode locations in a dipole-pole array. The blue dots then mark the location in the pseudo-section where the lines from Tx and Rx midpoints intersect and the data is plotted. By stepping through the Tx (current electrode pairs) using the slider you can see how the pseudo section is built up.\n",
    "\n",
    "The figures shown below show how the points in a pseudo-section are plotted for pole-dipole, dipole-pole, and dipole-dipole arrays. The color coding of the dots match those shown in the widget.\n",
    "<br />\n",
    "<br />\n",
    "\n",
    "<img src=\"https://github.com/geoscixyz/geosci-labs/blob/master/images/em/PoleDipole.png?raw=true\" style=\"width: 60%; height: 60%\"> </img> \n",
    "<center>Basic skematic for a uniformly spaced pole-dipole array.\n",
    "<br />\n",
    "<br />\n",
    "<br />\n",
    "\n",
    "<img src=\"https://github.com/geoscixyz/geosci-labs/blob/master/images/em/DipolePole.png?raw=true\" style=\"width: 60%; height: 60%\"> </img>\n",
    "<center>Basic skematic for a uniformly spaced dipole-pole array. \n",
    "<br />\n",
    "<br />\n",
    "<br />\n",
    "<img src=\"https://github.com/geoscixyz/geosci-labs/blob/master/images/em/DipoleDipole.png?raw=true\" style=\"width: 60%; height: 60%\"> </img>\n",
    "<center>Basic skematic for a uniformly spaced dipole-dipole array.\n",
    "<br />\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e3a9e46974df45fd85a177d8f340206d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "MyApp(children=(IntSlider(value=0, description='i', max=30), IntSlider(value=0, description='j', max=7), Toggl…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "surveyType = 'DipoleDipole'\n",
    "survey, xzlocs = DC2Dsurvey(np.ones(mesh.nC),surveyType)\n",
    "PseudoSectionWidget(survey,surveyType)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
